<?php
/**
 * 生成 library 自动加载项
 */

define('V_PATH', dirname(dirname(__FILE__)));

$libDir = V_PATH . '/library';
require_once $libDir.'/FS.php';
require_once $libDir.'/Str.php';

$list = FS::lsdir($libDir, FS::LIST_FILE, true);
sort($list);
$libraries = array();
foreach($list as $path) {
    $path = str_replace('\\', '/', $path);
    $resource = str_replace('.php', '', $path);
    $name = str_replace('/', '_', $resource);
    $contents = FS::read($libDir.'/'.$path);
    if (Str::has($contents, 'class ' . $name)) {
        $libraries[$name] = $resource;
    }
}

FS::write(V_PATH.'/_library.php', '<?php'.PHP_EOL.'return '.var_export($libraries, true).';');
echo 'generate library clases finished.', PHP_EOL;
